<?php
$lang=$_REQUEST['lang'];
$thoigian=$_REQUEST['thoigian'];
$nguoiguidi=$_REQUEST['nguoiguidi'];
$company=$_REQUEST['company'];
$listid=$_REQUEST['listid'];

/*$lang="VN";
$thoigian="2012-1";
$nguoiguidi="Đặng Kim Liên";
$company="elitech";
$listid="1323404319486";*/

$mnhanvien = explode(",", $listid);
$nhanvien="";
if(count($mnhanvien)>0){
	for($i=0;$i<count($mnhanvien);$i++){
		if($nhanvien==""){
			$nhanvien ="'".$mnhanvien[$i]."'";
		}else{
			$nhanvien .=",'".$mnhanvien[$i]."'";
		}
	}
}

if (empty($lang) || $lang == "EN") {
	$value = "value/value_en.php";
} else if($lang == "VN") {
	$value = "value/value_vn.php";
}
else {
	$value = "value/value_kr.php";
}
include($value);
include 'connection.php';

$query="SELECT sa_employee_salary.*, employee.FullName, employee.Position,employee.IDEmployee,employee.Email   
		from sa_employee_salary, employee 
		where employee.IDEmployee=sa_employee_salary.employeeID ";
		if($thoigian !=""){
			$query .=" and sa_employee_salary.sa_time='".$thoigian."'";
		}
		if($nhanvien!=""){
			$query .=" and  employee.IDEmployee in (".$nhanvien.") ";
		}
		$query .=" and employee.State=1";

$mkq=mysql_query($query);

require_once('class.phpmailer.php');

        

if(mysql_num_rows($mkq)>0){
	while($row=mysql_fetch_array($mkq)){
		$mail = new PHPMailer();

		$mail->IsSMTP();
		$mail->SMTPDebug  = 2;                    
		$mail->SMTPAuth   = true;                  
		$mail->SMTPSecure = "ssl";
		$mail->Host       = "smtp.gmail.com";     
		$mail->Port       = 465;                     
		$mail->Username   = "elisoftmailserver@gmail.com"; 
		$mail->Password   = "1234567892727";    
		$mail->SetFrom('elisoftsolution@gmail.com',$company);
		
		$mail->AddAddress($row[Email], $row[FullName]);
		
		$mail->Subject    =  $l_salary_detail." ".$thoigian;
		
		$mail->CharSet = "utf-8";
		$mail->IsHTML(true);
		
		
		$body ='<table width="100%"><tr><td style="padding:10px;color:black; font-weight:bold; font-size:13px;text-align:center;">'.$l_salary_detail." ".$thoigian.'</td></tr></table>';
		$body .='<table style="width:100%;border:1px #000000 solid;">';
				$body .='<tr style="background:#EEEEEE;font-weight:bold;text-align:center;border-bottom:1px #000000 solid;">';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_no.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_employee_name.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_position.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_number_time_work.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_num_allow_holiday.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_basicsalary.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_allowancebasicsalary.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_dayoff.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_absentmonth.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_comebackearly.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_comelately.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_allowanceSenior.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_allowanceC.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_salaryperday.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_salaryreceived.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_allowance_holiday.'</th>';
						$body .='<th colspan="2" style="border: 1px #000000 dotted">'.$l_allowance.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_allowance_hard.'</th>';
						$body .='<th colspan="2" style="border: 1px #000000 dotted">'.$l_allowance_overtime.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_total.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_socialInsurance.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_salary_bonus.'</th>';
						//$body .='<th rowspan="2" class="rf-dt-shdr-c">'.$l_salary_sub.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_realreceived.'</th>';
						$body .='<th rowspan="2" style="border: 1px #000000 dotted">'.$l_note.'</th>';
					$body .='</tr>';
					$body .='<tr>';
						$body .='<th style="border: 1px #000000 dotted">'.$l_lunch.'</th>';
						$body .='<th style="border: 1px #000000 dotted">'.$l_parking.'</th>';
						$body .='<th style="border: 1px #000000 dotted">'.$l_numbersession.'</th>';
						$body .='<th style="border: 1px #000000 dotted">'.$l_total_amount.'</th>';
					$body .='</tr>';
					$body .='<tr style="background: #93cddd; color: white;text-align:center;">';
						$body .='<td class="rf-dt-c"></td>';
						$body .='<td class="rf-dt-c">(2)</td>';
						$body .='<td class="rf-dt-c">(3)</td>';
						$body .='<td class="rf-dt-c">(4)</td>';
						$body .='<td class="rf-dt-c"></td>';
						$body .='<td class="rf-dt-c">(5)</td>';
						$body .='<td class="rf-dt-c">(6)</td>';
						$body .='<td class="rf-dt-c">(7)</td>';
						$body .='<td class="rf-dt-c">(8)</td>';
						$body .='<td class="rf-dt-c">(9)</td>';
						$body .='<td class="rf-dt-c">(10)</td>';
						$body .='<td class="rf-dt-c">(11)</td>';
						$body .='<td class="rf-dt-c">(12)</td>';
						$body .='<td class="rf-dt-c">(13)=[(5)+(6) +(11)+(12)]/4</td>';
						$body .='<td class="rf-dt-c">(14)=(13) x [(4)-7)]</td>';
						$body .='<td class="rf-dt-c">(15)</td>';
						$body .='<td class="rf-dt-c">(16)</td>';
						$body .='<td class="rf-dt-c">(17)</td>';
						$body .='<td class="rf-dt-c">(18)</td>';
						$body .='<td class="rf-dt-c">(19)</td>';
						$body .='<td class="rf-dt-c">(20)= 240000x(19)</td>';
						$body .='<td class="rf-dt-c">(21)=(14)+(15) +(16)+(17) +(28)+(20)</td>';
						$body .='<td class="rf-dt-c">(22)</td>';
						$body .='<td class="rf-dt-c">(23)</td>';
						//$body .='<td class="rf-dt-c">(24)</td>';
						$body .='<td class="rf-dt-c">(24)=(21)+(23)-(22)</td>';
						$body .='<td class="rf-dt-c"></td>';
					$body .='</tr>';
					$body .='<tr style="text-align:center;">';
						$body .='<td style="border: 1px #000000 dotted">1</td>';
						$body .='<td style="border: 1px #000000 dotted">'.$row[FullName].'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.$row[Position].'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.$row[really_number_time_work]."/".$row[number_time_work].'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.$row[number_allow_holiday].'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[basic_salary]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[allowance_basic_salary]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.$row[number_dateoff].'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.$row[number_holiday].'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.$row[number_is_comeback_early].'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.$row[number_is_late].'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[allowance_senior]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[allowance_c]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[oneday_salary]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[paid_salary]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[allowance_holiday]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[allowance_lunch]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[allowance_car]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[allowance_hard]).'</td>';	
						$body .='<td style="border: 1px #000000 dotted">'.$row[number_overtime].'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[overtime_salary]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[total_salary]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[insurance]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[salary_bornus]).'</td>';
						//$body .='<td class="rf-dt-c">'.number_format($row[salary_sub]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.number_format($row[received_salary]).'</td>';
						$body .='<td style="border: 1px #000000 dotted">'.$row[note].'</td>';
					$body .='</tr>';
					
				$body .='</table> ';
				$body .='<br><table width="100%" style="padding:20px" ><tr><td align="right"><b>'.$l_sender.':</b> <b><i>'.$nguoiguidi.'</i></b></td></tr></table>';
		$mail->Body = $body;
		$mail->AltBody=$dtitle;
		
		if(!$mail->Send()) {
			echo "<br><p style='width:100%;'>".$row[FullName]." -> ".$l_sendmail_fail." ". $mail->ErrorInfo."</p>";
		} else {
			echo "<br><p style='width:100%;'>".$l_sendmail_ok." ".$row[FullName]."</p>";
		}
	}
}


?>